%{
#include <string>

#include <map>
using std::string;
using std::map;
#define YYSTYPE const char *
#include <stdio.h>
#include "src/myheader.h"
extern "C" {
void yyerror(const char *s);
extern int yylex(void);
}
%}
%token IDENT NUM LABEL IF GOTO ASSIGN NEWLINE OP;
%%
input:line{codeTable.push_back(code());}
     |input line {codeTable.push_back(code());}
     ;
line:assign_expr NEWLINE
    |branch_expr NEWLINE
    ;
assign_expr:IDENT ASSIGN rightExpr{
		code &temp = codeTable.back();
		temp.def.insert($1);
	   };
rightExpr:IDENT {codeTable.back().use.insert($1);}
	 |rightExpr IDENT {codeTable.back().use.insert($2);}
	 ;
branch_expr:IF rightExpr GOTO IDENT {
		codeTable.back().jumpLabel = $4;
	   }
	   ;
%%
extern int yy_flex_debug;
int main(int argc , char **argv)
{
    //yy_flex_debug = 1;
    yydebug = (argc == 1);
    yyparse();
    generateCFG();
}
